import web

web.webapi.internalerror = web.debugerror
web.config.db_parameters = dict(dbn='postgres', user='liuqingy', pw='', db='test')
render = web.template.render('tmpl/')

urls = (
        '/', 'index',
        '/add', 'add',
        )

class index:
    def GET(self):
        todos = web.select('todo')
        print render.index(todos)

class add:
    def POST(self):
        i = web.input()
        n = web.insert('todo', title=i.title)
        web.seeother('./#t'+str(n))

if __name__ == "__main__":
    web.run(urls, globals(), web.reloader)
